package sample

import (
	"gorm.io/gorm"
	"organoid_public/domain/sample/model"
	"organoid_public/domain/sample/repository"
	"organoid_public/infrastructure/db"
)

type ProtocolRepository struct {
	db *gorm.DB
}

func NewProtocolRepository(db db.DefaultDb) repository.Protocol {
	return &ProtocolRepository{
		db: db,
	}
}

func (p *ProtocolRepository) ProcessList(sampleId string) ([]model.SampleProtocolProcess, error) {
	var processList []model.SampleProtocolProcess
	return processList, p.db.Model(&model.SampleProtocolProcess{}).Where("sample_id = ?", sampleId).Find(&processList).Error
}

func (p *ProtocolRepository) MediumList(sampleId string) ([]model.SampleProtocolMedium, error) {
	var mediumList []model.SampleProtocolMedium
	return mediumList, p.db.Model(&model.SampleProtocolMedium{}).Where("sample_id = ?", sampleId).Find(&mediumList).Error
}

func (p *ProtocolRepository) MaterialList(sampleId string) ([]model.SampleProtocolMaterial, error) {
	var materialList []model.SampleProtocolMaterial
	return materialList, p.db.Model(&model.SampleProtocolMaterial{}).Where("sample_id = ?", sampleId).Find(&materialList).Error
}

func (p *ProtocolRepository) KeyNodeList(sampleId string) ([]model.SampleProtocolKeyNode, error) {
	var keyNodeList []model.SampleProtocolKeyNode
	return keyNodeList, p.db.Model(&model.SampleProtocolKeyNode{}).Where("sample_id = ?", sampleId).Find(&keyNodeList).Error
}
